﻿using sy3_4;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _3_4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.Text = "Truck类";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
             
                int wheels = int.Parse(textBox1.Text);
                float weight = float.Parse(textBox2.Text);
                float maxLoad = float.Parse(textBox3.Text);
                float oilPerKm = float.Parse(textBox4.Text);
                float nowLoad = float.Parse(textBox5.Text);
                float runKm = float.Parse(textBox6.Text);

             
                Truck truck = new Truck(wheels, weight, maxLoad, oilPerKm);
                truck.SetVehicle(nowLoad, runKm);

              
                if (truck.Overload())
                {
                    MessageBox.Show("对不起！卡车已超重，请卸下一些货物。", "提示");
                    textBox5.Text = "";
                    textBox5.Focus();
                }
                else
                {
                    float totalOil = truck.OilConsumption();
                    MessageBox.Show($"卡车正在行驶中...\n现已耗油{totalOil}升！", "提示");
                    truck.GetVehicle(); 
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("请输入有效的数值！", "错误");
            }
        }
    }
}
namespace sy3_4
{
    public class Vehicle
    {
        protected int wheels;   
        protected float weight; 

        
        public Vehicle(int wheels, float weight)
        {
            this.wheels = wheels;
            this.weight = weight;
        }

     
        public virtual void SetVehicle() { }

        
        public virtual void GetVehicle() { }
    }
}


namespace _3_4
{
    public class Truck : Vehicle
    {
        private float maxLoad;   
        private float oilPerKm;    
        private float nowLoad;    
        private float runKm;      

       
        public Truck(int wheels, float weight, float maxLoad, float oilPerKm)
            : base(wheels, weight)
        {
            this.maxLoad = maxLoad;
            this.oilPerKm = oilPerKm;
        }

        public void SetVehicle(float nowLoad, float runKm)
        {
            this.nowLoad = nowLoad;
            this.runKm = runKm;
        }

       
        public override void SetVehicle()
        {
            base.SetVehicle();
        }

       
        public override void GetVehicle()
        {
            MessageBox.Show(
                "车轮数：" + wheels + "\n车重量：" + weight +
                "\n载重量：" + maxLoad + "\n每公里耗油：" + oilPerKm,
                "卡车信息"
            );
        }

      
        public bool Overload()
        {
            return nowLoad > maxLoad;
        }

        public float OilConsumption()
        {
            return runKm * oilPerKm;
        }
    }
}
namespace _3_4
{
    public class Vehicle
    {
        protected int wheels;   
        protected float weight; 

  
        public Vehicle(int wheels, float weight)
        {
            this.wheels = wheels;
            this.weight = weight;
        }

       
        public virtual void SetVehicle() { }

        public virtual void GetVehicle() { }
    }
}